package io.yunho.yunho.interview.two.juc;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

@Getter
@ToString
@AllArgsConstructor
class User{
    String username;
    int age;
}

/**
 * Created by Administrator on 2020/4/13.
 */
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User z3= new User("z3",23);
        User l4= new User("l4",50);

        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(z3);
        System.out.println(atomicReference.compareAndSet(z3, l4)+"\t"+atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(z3, l4)+"\t"+atomicReference.get().toString());
    }
}
